/**
 * 
 */
package cn.gov.msa.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageHelper;

import cn.gov.msa.dao.DictionaryDetailMapper;
import cn.gov.msa.dao.DictionaryMapper;
import cn.gov.msa.dao.RoleMapper;
import cn.gov.msa.model.DeclareItem;
import cn.gov.msa.model.Dictionary;
import cn.gov.msa.model.DictionaryDetail;
import cn.gov.msa.model.Role;
import cn.gov.msa.pagehelper.CustomPageHelper;
import cn.gov.msa.service.DictionaryService;
import cn.gov.msa.service.RoleService;
import net.sf.json.JSONObject;

/**
 * @author Administrator
 *
 */
public class RoleServiceImpl implements RoleService {


	@Autowired
	private RoleMapper roleMapper;

	public int deleteRole(String rolecode) throws Exception {
		int result = roleMapper.deleteByPrimaryKey(rolecode);
		
		return result;
	}

	

	public boolean saveData(Role role) throws Exception {
		boolean result = false;
				
		int irole = roleMapper.insert(role);
		
		if(irole > 0)
			result = true;
		
		return result;
	}
	

	public boolean updateData(Role role) throws Exception {
		boolean result = false;
		
		int irole = roleMapper.updateByPrimaryKey(role);
		
		
		if(irole > 0)
			result = true;
		
		return result;
	}



	public List<Role> selectRole(int pageNum, int pageSize, Role role) throws Exception {

		CustomPageHelper.startPage(pageNum, pageSize); // 核心分页代码  
		List<Role> listRole = roleMapper.selectData(role);
		
		return listRole;
	}
	
	
	public Role getInfoByRoleCode(String rolecode) throws Exception {
        
        //读取数据库信息
		Role role = roleMapper.selectByPrimaryKey(rolecode);

	    return role;
	}

	@Override
	public List<Role> selectAllRole() throws Exception {

		List<Role> listRole = roleMapper.selectData(null);
		
		return listRole;
	}
}
